﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace ZuoAlgorithms.Class014;

// 用栈实现队列
// 用队列实现栈
public class ConvertQueueAndStack
{
    // 测试链接 : https://leetcode.cn/problems/implement-queue-using-stacks/
    class MyQueue
    {
        public Stack<int> ins;
        public Stack<int> outs;

        public MyQueue()
        {
            ins = new Stack<int>();
            outs = new Stack<int>();
        }

        // 倒数据
        // 从in栈，把数据倒入out栈
        // 1) out空了，才能倒数据
        // 2) 如果倒数据，in必须倒完
        private void InToOut()
        {
            if (outs.Count == 0)
            {
                while (ins.Count != 0)
                {
                    outs.Push(ins.Pop());
                }
            }
        }

        public void Push(int x)
        {
            ins.Push(x);
            InToOut();
        }


        public int Pop()
        {
            InToOut();
            return outs.Pop();
        }

        public int Peek()
        {
            InToOut();
            return outs.Peek();
        }

        public bool IsEmpty()
        {
            return ins.Count == 0 && outs.Count == 0;
        }
    }

    // 测试链接 : https://leetcode.cn/problems/implement-stack-using-queues/
    class MyStack
    {
        Queue<int> queue;

        public MyStack()
        {
            //queue = new LinkedList<int>();
        }

        public void Push(int x)
        {
            int n = queue.Count;
        }

        public int Pop()
        {
            return queue.Peek();
        }

        public int Top()
        {
            return queue.Peek();
        }

        public bool IsEmpty()
        {
            return queue.Count == 0;
        }
    }
}